package com.aaa.stock.controller.api;

import com.aaa.entity.Medicines;
import com.aaa.entity.Provider;
import com.aaa.entity.Purchase;
import com.aaa.entity.PurchaseItem;
import com.aaa.stock.service.ExamineService;
import com.aaa.stock.service.PurchaseService;
import com.aaa.stock.vo.ExamineVo;
import com.aaa.stock.vo.PurchaseVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.Objects;


@RestController
@RequestMapping("stock/api/examine")
public class ApiExamineController {
    @Autowired
    private ExamineService examineService;

    @PostMapping("queStatus/{currentPage}/{pageSize}")
    public Result<IPage<Purchase>> pasi(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody ExamineVo examineVo
    ){
        return examineService.findBystatus(currentPage,pageSize,examineVo);
    }

    @PostMapping("addexam")
    public Result<Boolean> addexam(@RequestBody Purchase purchase) {
        System.out.println("purchase***********************"+ purchase);
        if (Objects.nonNull(purchase.getPurchaseId())){
            purchase.setUpdateTime(LocalDateTime.now());
        }else {
            purchase.setCreateTime(LocalDateTime.now());
        }
        return examineService.add(purchase);
    }


    @PostMapping("noexamine")
    public Result<Boolean> noexamine(@RequestBody Purchase purchase) {
        System.out.println("purchase***********************"+ purchase);
        if (Objects.nonNull(purchase.getPurchaseId())){
            purchase.setUpdateTime(LocalDateTime.now());
        }else {
            purchase.setCreateTime(LocalDateTime.now());
        }
        return examineService.noadd(purchase);
    }

    @PostMapping("quet/{purchaseId}")
    public Result quet(@PathVariable String purchaseId){
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++"+purchaseId);
        return examineService.quet(purchaseId);
    }


}
